package com.mju.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import com.mju.dao.UsersMapper;
import com.mju.model.Users;
import com.mju.model.dto.UserInfo;
import com.mju.service.UsersService;

@Service
public class UsersServiceImpl implements UsersService {

	@Value("${custom.defaultpasswd}")
	private String defaultpasswd;
	
	@Autowired
	private PasswordEncoder passwordEncoder;
	@Autowired
	private UsersMapper usersMapper;
	
	private String genPasswd() {
		return passwordEncoder.encode(defaultpasswd);
	}
	
	@Override
	public int resetAllPasswd() {
		// TODO Auto-generated method stub
		return usersMapper.resetAllPasswd(this.genPasswd());
	}

	@Override
	public int resetPasswd(String studentno) {
		Users u=usersMapper.selectByPrimaryKey(studentno);
		u.setPasswd(this.genPasswd());
		return usersMapper.updateByPrimaryKey(u);
	}

	@Override
	public UserInfo getUserInfo(String studentno) {
		return usersMapper.getUserInfo(studentno);
	}

}
